package com.heima.search.pojos;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author Mr.M
 * @version 1.0
 * @description 文章信息索引库实体
 * @date 2024/8/18 20:26
 */
@Data
@ApiModel(description = "文章信息索引库实体")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Document(indexName = "app_info_article")
public class ArticleDoc {

    @Id
    @ApiModelProperty("文章ID")
    private Long id;

    @ApiModelProperty("发布时间")
    @Field(type = FieldType.Date)
    private LocalDateTime publishTime;

    @ApiModelProperty("布局类型")
    @Field(type = FieldType.Integer)
    private Integer layout;

    @ApiModelProperty("图片地址")
    @Field(type = FieldType.Keyword, index = false)
    private String images;

    @ApiModelProperty("静态页面URL")
    @Field(type = FieldType.Keyword, index = false)
    private String staticUrl;

    @ApiModelProperty("作者ID")
    @Field(type = FieldType.Long)
    private Long authorId;

    @ApiModelProperty("作者名称")
    @Field(type = FieldType.Text)
    private String authorName;

    @ApiModelProperty("文章标题")
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    @MultiField(
            mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word"),
            otherFields = {
                    @InnerField(suffix = "keyword", type = FieldType.Keyword)
            }
    )
    private String title;

    @ApiModelProperty("文章内容")
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String content;

    @ApiModelProperty("全文搜索字段")
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String all;

    // 其他字段保持不变...
    @ApiModelProperty("自动补全字段")
    @CompletionField(analyzer = "ik_max_word")
    private List<String> suggestion;
}